$data.Entity.extend('Qcm', {
	id: { type: 'int', key: true, required: true },	
	titre: { type: 'string',required: true },
	description: { type: 'string',required: true },
	niveau: { type: 'string',required: true },
	difficulte: { type: 'string',required: true },
	auteur: { type: 'string',required: true },
	date_creation: { type: 'string',required: true },  
	theme_id: { type: 'int',required: true}	
});


function getValueQcms(BD,champs,valeur){
	return BD.Qcms.filter('it.'+champs+' == '+valeur).toArray();
}

function getValueQcmsAndQuestions(BD,champs,valeur){
	
	return $.when(BD.Qcms.filter('it.'+champs+' == '+valeur).toArray()).then(function(qcms){
		var listeQcms = [];		
		var listeQuestions = [];	
		
		qcms.forEach(function(qcm){
			listeQuestions.push(getValueQuestionsAndReponses(BD,'qcm_id',qcm.id));			
			listeQcms.push(qcm);			
		});
			
		if(listeQcms.length == 0){			
			return listeQcms;
		}
	
		return $.when.apply($, listeQuestions).then(function(){
			
			for( var i = 0; i < arguments.length; i++ ) {
				listeQcms[i].questions =  arguments[i];
			}

			return listeQcms;
		});
	});
}